package typejump.commands;

import typejump.GameIO;
import typejump.engine.GameEngine;

public class DevLevel implements TextCommand {

	@Override
	public boolean matches(String command) {
		return command.matches("dev ((save)|(load)) level [a-zA-Z0-9]+");
	}

	@Override
	public void act(String command) {
		String[] parts = command.split(" ");
		boolean load = parts[1].equals("load");
		String fname = parts[3];
		
		boolean p = GameEngine.isPaused();
		GameEngine.setPaused(true);
		
		String response = null;
		if (load) {
			response = GameIO.loadLevel(fname);
		} else {
			response = GameIO.writeLevel(fname);
		}
		
		GameEngine.setInitialPlayerPosition();
		
		if (response != null) {
			GameEngine.addTextEffect(response, "dev.fail");
		} else {
			GameEngine.addTextEffect(command.toUpperCase(), "dev.pass");
		}
		GameEngine.setPaused(p);
	}
}
